<?php
/**
 * Terminarz z charmonogramem zadań, godzin przyjęć lekarzy itp. 
 * 
 * @author $Author$
 * @version $Id$
 */
class Schedule_IndexController extends Promotor_Controller_Action 
{
	public $skin = array(
		'index' => array(
			'layout' => 'schedule'
		)
	);

	public function init()
	{
		$this->view->schedule = $this->_getParam('schedule');
		$this->view->username = (int) $this->_getParam('username');
		// Jeżeli uzytkownik jest mniejszy od 1 to są to wszystkie rekordy z danego terminarza!
		if ($this->view->username < 1)
		{
			$this->view->username = null;
		}
	}
	
	/**
	 * Strona główna
	 * @return void
	 */
	public function indexAction()
	{
		$model = new Schedule_Model_Schedule();
		if (null === ($info = $model->findScheduleInfo($this->view->schedule)))
		{
			$this->renderScript('index/scheduleNoExsists.phtml');
			return;
		}

		$this->view->assign($info);
	}

	/**
	 * Route: /schedule/:username/:id
	 * @return void
	 */
	public function eventsAction()
	{
		/* @var $viewRenderer Zend_Controller_Action_Helper_ViewRenderer */
		$viewRenderer = $this->_helper->getHelper('ViewRenderer');
		$viewRenderer->setNeverRender(true);

		/* @var $layout Zend_Layout_Controller_Action_Helper_Layout */
		$layout = $this->_helper->getHelper('Layout');
		$layout->disableLayout();


		$model = new Schedule_Model_Event();
		$result = $model->findEvents($this->view->schedule, 
									 $this->view->username);

		$data = array(
			'status'   => $model->getStatus(),
			'result'   => $result,
			'messages' => $model->getMessages()
		);

		/* @var $json Zend_Controller_Action_Helper_Json */
		$json = $this->getHelper('Json');
		$json->sendJson($data);
	}
}